package com.syy.reducejoin;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class OrderJoinMapper extends Mapper<LongWritable, Text, OrderJoin, NullWritable> {
    private OrderJoin orderJoin = new OrderJoin();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String s = value.toString();
        String[] split = s.split("\t");
        if (split.length > 2) {
            orderJoin.setOid(split[0]);
            orderJoin.setPid(split[1]);
            orderJoin.setCount(Integer.parseInt(split[2]));
            orderJoin.setpName("");
        }else {
            orderJoin.setpName(split[1]);
            orderJoin.setPid(split[0]);
            orderJoin.setOid("");
            orderJoin.setCount(0);
        }
        context.write(orderJoin, NullWritable.get());
    }
}
